﻿/********************************************************************************
** @ Date:2025/06/26
** @ Author: Gaojia
** @ Description: 轮播单个显示界面
** @ Version:1.0.0
** @ Fun:
********************************************************************************/
#ifndef UCarouseshowPage_H
#define UCarouseshowPage_H

#include <QWidget>
#include <QGridLayout>
#include <QVector>
#include <QLabel>
#include <QResizeEvent>
#include "UWidgetRestorer.h"
#include "CPageCarouse.h"
#include "ui_UCarouseshowPage.h"

struct SCarouseInfo
{
	QString sGuid;
	QString sCardGuid;
	int nRow;
	int nCol;
	int nRowSpan;
	int nColSpan;
	QWidget *pWidget;
	UWidgetRestorer *pRestorer;
	SCarouseInfo()
	{
		nRow = 0;
		nCol = 0;
		nRowSpan = 1;
		nColSpan = 1;
		pWidget = NULL;
	}
	SCarouseInfo(QString sId, QString sCardId, int Row, int Col,QWidget *pW, int RowSpan = 1, int ColSpan = 1)
	{
		sGuid = sId;
		sCardGuid = sCardId;
		nRow = Row;
		nCol = Col;
		nColSpan = ColSpan;
		nRowSpan = RowSpan;
		pWidget = pW;
	}

}; 



class UCarouseshowPage : public QWidget
{
	Q_OBJECT

public:
	UCarouseshowPage(CPageCarouse *pPage, QWidget *parent = nullptr);
	~UCarouseshowPage();
	void refushDate(bool bRefush);   //开始或者停止刷新数据
protected:
	void resizeEvent(QResizeEvent* event) override;
	void showEvent(QShowEvent* event);
	void hideEvent(QHideEvent* event);
private:
	void initUi();  //初始化界面
	void addGridWidget(SPageItem item,QWidget *pW); //往网格里面添加控件
	void updateGridLayoutSize();   // 动态适配控件尺寸
	QWidget * getDevWidget(QString sGuid, QString sCardGuid);  //获取设备缩略图
private:
	Ui::UCarouseshowPageClass ui;
	CPageCarouse *m_pPageCarouse;
	QGridLayout *m_pGridLayout;
	QVector<SCarouseInfo*> m_carouse;
	QVector<QRect> m_widgetGridRects; // 保存控件在网格中占用区域
	QString m_sPageqssStr;   //界面样式表
	QString m_sCardqssStr;   //卡片样式表
	bool m_bRefush;
	const int m_gridRows = 4;
	const int m_gridCols = 4;
};
#endif